import {
	ref
} from 'vue'
import {
	defineStore
} from 'pinia'
import {
	fetchDeviceList,
	fetchAlarmsList
} from '@/api/home'
import {
	throttle
} from '@/utils/index.js'
export const useMarkerStore = defineStore('marker', () => {
	const markers = ref([])

	const getMarkers = throttle(async function(query) {
		const params = {
			...query,
			page: 1,
			limit: 200
		}
		const res = await fetchDeviceList(params)
		res.map(i => {
			i.width = 26
			i.height = 32
			i.iconPath = '/static/marker/normal.png'
			i.causedBy = 'normal'
			if (i.is_abnormal == 1) {
				i.iconPath = '/static/marker/exception.png'
				i.causedBy = 'exception'
			}
			i.callout = {
				content: 99
			}
		})
		//console.log(res)
		markers.value = res
	}, 300)

	function add(marker) {
		markers.value = markers.value.concat(marker)
	}

	function clearMarkers() {
		markers.value = []
	}

	return {
		markers,
		add,
		getMarkers,
		clearMarkers
	}
})